//
//  DYThemeViewModel.m
//  BaiSi
//
//  Created by mac on 16/10/29.
//  Copyright © 2016年 DeYi. All rights reserved.
//

#import "DYThemeViewModel.h"
#import "DYThemeItem.h"
#import "DYThemeHotReviewItem.h"


@implementation DYThemeViewModel

- (void)setItem:(DYThemeItem *)item {
    _item = item;
    //计算顶部View尺寸
    CGFloat margin = 10;
    CGFloat topX = 0;
    CGFloat topY = 0;
    CGFloat topW = DYScreenW;
    CGFloat textW = DYScreenW - 2 * margin;
    CGFloat textH = [item.text sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(textW, MAXFLOAT)].height;
    CGFloat topH = 65 + textH;
    _topViewFrame = CGRectMake(topX, topY, topW, topH);
    
    //计算cell高度
    _cellHeight =CGRectGetMaxY(_topViewFrame) + margin;
    
    //中间View 判断是否有图片
    if (item.type != MyTextType) {//有图片
        CGFloat photoX = margin;
        CGFloat photoY = _cellHeight;
        CGFloat photoW = DYScreenW - 2 * margin;
        CGFloat photoH = (photoW / item.width) * item.height;
        //计算是否是大图
        if (photoH > DYScreenH) {
            item.is_big = YES;
            photoH = DYBigPictureH;
        }
        _middleViewFrame = CGRectMake(photoX, photoY, photoW, photoH);
        _cellHeight =CGRectGetMaxY(_middleViewFrame) + margin;
    
    }
    
    //最热评论
    if (item.hotItem) {
        CGFloat HotTemp = 21;
        CGFloat hotX = margin;
        CGFloat hotY = _cellHeight;
        CGFloat hotW = DYScreenW - 2 * margin;
        CGFloat hotH = HotTemp + 21;
        if (item.hotItem.content.length) {
            textH = [item.hotItem.allContent sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(hotW, MAXFLOAT)].height;
            hotH = HotTemp + textH;
        }
        _HotReviewFrame = CGRectMake(hotX, hotY, hotW, hotH);
        _cellHeight = CGRectGetMaxY(_HotReviewFrame) + margin;
    }
    
    //底部视图
    _bottomViewFrame = CGRectMake(0, _cellHeight, DYScreenW, 35);
    _cellHeight = CGRectGetMaxY(_bottomViewFrame);
   
}

@end
